import {SAVE_JUMP_RUN, SAVE_MELT_GRAD, SAVE_PCR_ALL_CYCLE, SAVE_PCR_RUN_ALL_CYCLE, SAVE_SCAN_CHANNEL, SAVE_STAGES} from "./constants";
import {AMPLIFICATION, HOLD} from "../config";
import {getScanChannel} from "../../../../common/utils";

const defaultState = {
  stages: [{
    state: HOLD,
    steps: [{
      temperature: 95.0,
      gradient: 0.5,
      time: 300,
      record: false,
      autoDelta: {
        checkAutoPauseBefore: false,
        checkAutoPauseAfter: false,
        checkAutoDeltaTemperature: false,
        autoDeltaTemperature: 0.5,
        checkAutoDeltaTime: false,
        autoDeltaTime: 0,
        checkRampRate: false,
        rampRate: 0.1
      },
      gradientDeltaTemperature: {
        checked: false,
        start: 65.0,
        end: 65.0
      }
    }],
    cycle: 1,
    hrMeltingCurveMode: false
  }, {
    state: AMPLIFICATION,
    steps: [{
      temperature: 95.0,
      gradient: 0.5,
      time: 30,
      record: false,
      autoDelta: {
        checkAutoPauseBefore: false,
        checkAutoPauseAfter: false,
        checkAutoDeltaTemperature: false,
        autoDeltaTemperature: 0.5,
        checkAutoDeltaTime: false,
        autoDeltaTime: 0,
        checkRampRate: false,
        rampRate: 0.1
      },
      gradientDeltaTemperature: {
        checked: false,
        start: 95.0,
        end: 95.0
      }
    }, {
      temperature: 60.0,
      gradient: 0.5,
      time: 30,
      record: true,
      autoDelta: {
        checkAutoPauseBefore: false,
        checkAutoPauseAfter: false,
        checkAutoDeltaTemperature: false,
        autoDeltaTemperature: 0.5,
        checkAutoDeltaTime: false,
        autoDeltaTime: 0,
        checkRampRate: false,
        rampRate: 0.1
      },
      gradientDeltaTemperature: {
        checked: false,
        start: 95.0,
        end: 95.0
      }
    }],
    cycle: 40,
    hrMeltingCurveMode: false
  }],
  scanChannel: getScanChannel(),
  isJump2Run: false,
  pcrAllCycle: 40,  //  Amplification所有的cycle总和
  pcrAllRunCycle: 40,  //  只在Run界面里同步更新Amplification所有的cycle总和
  meltGrad: {
    minX: 60,
    maxX: 95
  }
};

export default function reducer(state = defaultState, action) {
  switch (action.type) {
    case SAVE_STAGES :
      return {...state, stages: action.stages};
    case SAVE_SCAN_CHANNEL :
      return {...state, scanChannel: action.scanChannel};
    case SAVE_JUMP_RUN :
      return {...state, isJump2Run: action.isJump2Run};
    case SAVE_PCR_ALL_CYCLE :
      return {...state, pcrAllCycle: action.pcrAllCycle};
    case SAVE_PCR_RUN_ALL_CYCLE :
      return {...state, pcrAllRunCycle: action.pcrAllRunCycle};
    case SAVE_MELT_GRAD :
      return {...state, meltGrad: action.meltGrad};
    default:
      return state;
  }
}